<template>
  <a-card>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="6">
            <a-form-item label="物料代码">
              <a-input
                type="list"
                v-model="queryParam.productCode"
                @keyup.enter.native="searchQuery('productCode', queryParam.productCode)"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="6">
            <a-form-item label="物料名称">
              <a-input
                type="list"
                v-model="queryParam.productName"
                @keyup.enter.native="searchQuery('productName', queryParam.productName)"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :md="6" :sm="6">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <!--              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>-->
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--              <a-button @click="handleAdd" type="primary" icon="plus" style="margin-left: 8px">新增</a-button>-->
              <a-button @click="exportDataEvent" type="primary" icon="plus" style="margin-left: 8px">导出</a-button>
              <j-super-query
                :field-list="superQueryFieldList"
                ref="superQueryModal"
                @handleSuperQuery="handleSuperQuery"
                style="margin-left: 8px"
              ></j-super-query>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <j-vxe-table
      ref="table"
      bordered
      resizable
      highlight-current-row
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :export-config="{}"
      @change="handleTableChange"
    >
      <span slot="action" slot-scope="text, record">
        <a @click="handleEdit(record)">编辑</a>
        <a-divider type="vertical" />
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
          <a>删除</a>
        </a-popconfirm>
      </span>
    </j-vxe-table>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@api/manage'

export default {
  name: 'HfPurchaseInputSummary',
  mixins: [JeecgListMixin],
  data() {
    return {
      description: '采购汇总表',
      // 表头
      columns: [
        {
          title: '物料代码',
          key: 'materialCode'
        },
        {
          title: '物料名称',
          key: 'materialName'
        },
        {
          title: '规格型号',
          key: 'sap'
        },
        {
          title: '单位',
          key: 'unit'
        },
        {
          title: '单箱数',
          key: 'perNumber'
        },
        {
          title: '箱数',
          key: 'number'
        },
        {
          title: '数量',
          key: 'totalNumber'
        }
      ],
      url: {
        list: '/purchase/hfPurchaseInput/summaryList'
      },
      superQueryFieldList: [],
      superQueryFlag: false,
      superQueryParams: ''
    }
  },
  created() {
    this.getSuperFieldList()
  },
  methods: {
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() //查询条件
      this.loading = true
      getAction(this.url.list, params)
        .then(res => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    /**
     *
     * @param field 字段名
     * @param value 字段值
     */
    searchQuery(field, value) {
      let data = this.dataSource
      this.dataSource = data.filter(d => {
        return d[field].includes(value) == -1
      })
      this.selectedRowKeys = []
      this.selectionRows = []
    },
    exportDataEvent() {
      this.$refs.table.openExport({ types: ['csv'] })
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'date', value: 'documentDate', text: '单据日期' })
      this.superQueryFieldList = fieldList
    },
    searchReset() {
      this.queryParam = {}
      this.$refs.superQueryModal.handleReset()
      this.loadData(1)
    }
  }
}
</script>

<style scoped></style>
